package com.zh.streamdemo.demo1;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

public class DemoSorted {

    public static void main(String[] args) {
        //默认正序（小的在前）
        Stream.of("1", "3", "2","4","0","9","7").map(Integer::parseInt).sorted().forEach(System.out::println);
        Stream.of("1", "3", "2","4","0","9","7").sorted().forEach(System.out::println);

        List<Map<String, Object>> lm = new ArrayList<>();
        for (int i = 1;i < 9;i++){
            Map<String, Object> m = new HashMap<>();
            m.put("date","2022-12-0"+i);
            lm.add(m);
        }
        lm.stream().sorted(DemoSorted::orderDate).forEach(System.out::println);
    }

    private static int orderDate(Map<String, Object> m1, Map<String, Object> m2){
        //正序（小的在前）
        //return m1.get("date").toString().compareTo(m2.get("date").toString());

        //倒序（大的在前）
        return m2.get("date").toString().compareTo(m1.get("date").toString());
    }
}
